import wx.grid

class MoveList(wx.grid.Grid):
    current_move = 0
    def __init__(self, parent):
        wx.grid.Grid.__init__(self, parent, wx.ID_ANY, size = (206,128))
        self.CreateGrid(40,2)
        self.SetColLabelValue(0,"White")
        self.SetColLabelValue(1,"Black")
        self.SetRowLabelSize(40)
        self.SetDefaultColSize(75)
        self.DisableDragColSize()
        self.DisableDragRowSize()
        self.EnableEditing(False)
        
    def publishMove(self, movetext):
        if self.GetNumberRows() <= self.current_move/2: self.AppendRows(1)
        self.SetCellValue(self.current_move/2, self.current_move%2, movetext)
        self.current_move += 1
        
    def takeBack(self):
        self.current_move -= 1
        if self.current_move < 0: self.current_move = 0
        self.SetCellValue(self.current_move/2, self.current_move%2, "")
    
    def clear(self):
        self.ClearGrid()
        self.current_move = 0

if __name__ == '__main__':
    from ChessController import BasicController
    
    app = wx.PySimpleApp()
    size = (520,520)
    frame = wx.Frame(None, wx.ID_ANY, "Chess game with movelist test application")
    list = MoveList(frame)
    controller = BasicController(frame, size, list)

    sizer = wx.BoxSizer(wx.HORIZONTAL)    
    sizer.Add(controller, 1, wx.EXPAND)
    sizer.Add(list, 0, wx.EXPAND)
    frame.SetSizer(sizer)
    
    controller.SetMinSize((520,520))
    frame.Fit()
    frame.Show()
    app.MainLoop()
